package org.quartz.No01简单的定时任务;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;

public class SimpleDemoJob implements Job {
    private static Connection getConn() {
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/myds";
        String username = "root";
        String password = "root";
        Connection conn = null;
        try {
            Class.forName(driver); //classLoader,加载对应驱动
            conn = (Connection) DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        System.out.println("成功加载MySQL驱动程序");
        return conn;
    }
    public void execute(JobExecutionContext context) throws JobExecutionException, SQLException {
        String sql;
        System.out.println("Hello World! - " + new Date());
        //do more...
        Connection conn = getConn();
        Statement stmt = conn.createStatement();
        sql = "insert into qrtz_job_details(JOB_NAME,JOB_DATA) values('name1','data1')";
        int result = stmt.executeUpdate(sql);
        System.out.print("result: "+result);

    }
}